package com.snailhd.common.util;

/**
 * @ClassName StringUtil
 * @Description
 * @Author hd
 * @Date 2019-06-12 15:10
 */
public class StringUtil {

    public final static char UNDERLINE = '_';

    /**
     * 转驼峰
     * 默认首字母小写
     */
    public static String camelCase(String str){
        return camelCase(str,false);
    }

    /**
     * 转驼峰
     */
    public static String camelCase(String str,boolean firstUpper){
        return camelCase(str,firstUpper,UNDERLINE);
    }

    /**
     * 转驼峰
     */
    public static String camelCase(String str,boolean firstUpper,char separator){
        if (str==null||"".equals(str.trim())){
            return "";
        }
        int len=str.length();
        StringBuilder sb=new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = Character.toLowerCase(str.charAt(i));
            if (c == separator){
                if (++i<len){
                    sb.append(Character.toUpperCase(str.charAt(i)));
                }
            }else{
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
